data = [
            ['1','2','3'],
            ['3','4','5'],
            ['6','7','8']
            ]
headers = ['one','two','three']


paths = {1:'/static/',
        2:'../static/',
        3:'../../static/',
        4:'../../../static/',
        5:'../../../../static/',
        6:'../../../../../static/',
        7:'../../../../../../static/',
        8:'../../../../../../../static/',}



def path(wsgi_path):
    d = wsgi_path.split('/')
    d = len(d)-1
    return paths[d]

# REMOVE THIS
class NotFound(object):
    def __init__(self, context):
        self.name = "Not found"
        self.message = "Page not found"
        self.path = path(context.path)
# REMOVE THIS        

class Found(object):
    def __init__(self, context):
        self.name = "Not named"
        self.path = path(context.path)
        
class Page(object):
    '''Create an object to contain default values that are then inserted in
    templates'''    
    def __init__(self, context):
        self.title = None
        self.message = None
        self.noun = ""
        self.verb = ""
        self.path = self.path = path(context.path)
        self.editable = False
        self.login = False
        self.cache = False
        self.table = False
        self.form = False
        # self.editable_table = False
        
    def update(self):
        '''Create a page title if one has not already been set'''
        if not self.title:
            self.title = '{0} / {1}'.format(self.verb, self.noun)
        if not self.title:
            self.title = u'Default' #M_DO: Replace with a CONFIG name
        
class Table():
    def __init__(self, data, headers, caption=None, width=None, button=None, edit=False):
        self.data = data
        self.headers = headers
        self.caption = caption
        if width: self.width = 'width = {0}'.format(width)
        else: self.width = ''
        self.button = button
        self.edit = edit
    
    def render(self):
        #border="0" cellpadding="0" cellspacing="1" 
        html = u''
        if self.edit:
            html+=u'<form name="main" method="post">\n'
        if self.button:
            html +='''
            <div id="table">
           <ul class="tabs">
               <li><a href = '/asd'>Edit</a></li>
            </ul>  
            </div> 
            '''
            
        html += u'<table {0}>\n'.format(self.width)
        html += u'<caption>{0}</caption>'.format(self.caption)
        if self.headers:
            html += u'\t<thead >\n\t<tr>\n'
            for h in self.headers:
                html += u'\t\t<th class="header">{0}</th>\n'.format(h)
            html += u'\t</tr>\n\t</thead>\n\t<tbody>\n'
            
        for row in self.data:
            html +=u'\t<tr>\n'
            for col in row:
                html += u'\t\t<td class="row">{0}</td>\n'.format(col)
            html +=u'\t</tr>\n'                
        html+=u'\t<tbody>\n</table>'
        if self.edit:
            html+= u'<input type="submit" value="Save" class="button" />'
            html+= u'\n</form>' 
        return unicode(html)
        

if __name__=='__main__':
    # print static_url('style.css',  2)
#    print path('/asdas/asdad')  
    pass

    t = Table(data, headers)
    print t.render()
    



# TEST: url function

#Junk 0907
#def static_url(name, depth):
#    return '{0}{1}'.format(paths[depth],name)
#
#def static_path(depth):
#    return paths[depth]